package com.hangar.eforms.common;

import lombok.Data;


/**
 * @author hwn
 */
@Data
public class Result<T> {

    private int code;
    private String msg;

    private T data;

    public static<T> Result<T> success(T data){
        Result<T> result = new Result<>();
        result.setCode(200);
        result.setMsg("success");
        result.setData(data);
        return result;
    }

    public static<T> Result<T> success(T data, String message){
        Result<T> result = new Result<>();
        result.setCode(200);
        result.setMsg(message);
        result.setData(data);
        return result;
    }

    public static<T> Result<Object> success(){
        Result<Object> result = new Result<>();
        result.setCode(200);
        result.setMsg("success");
        return result;
    }

    public static<T> Result<String> error(String msg){
        Result<String> result = new Result<>();
        result.setCode(500);
        result.setMsg(msg);
        return result;
    }

    public static<T> Result<String> error(int errorCode, String message){
        Result<String> result = new Result<>();
        result.setCode(errorCode);
        result.setMsg(message);
        return result;
    }

    public static<T> Result<String> error(){
        Result<String> result = new Result<>();
        result.setCode(500);
        result.setMsg("error");
        return result;
    }

}
